Component({
  /**
   * 组件的属性列表
   */
  properties: {
    hours:Number,//结束的小时
    curTimer: Number, //当前时间戳
    callback: String, // 回调
    clearTimer: Boolean // 清除定时器
  },

  /**
   * 组件的初始数据
   */
  data: {
    time: '',
    font:'',//结束后的提示
    flag:false
  },
  ready() {
    this.getFinalTime();
  },

  /**
   * 组件的方法列表
   */
  methods: {
    init() {
      const self = this;
      setTimeout(() => {
        self.getFinalTime.call(self);
      }, 1000);
    },
    getFinalTime() {
      // console.log( new Date().getTime())
      const data = this.data;
      // console.log(data)
      const gapTime = Math.ceil(((data.curTimer) + (data.hours) * 1000 - new Date().getTime())/1000); // 距离结束时间(10小时||2小时)
      let time = '00:00:00';
      if(gapTime > 0) {
        let lastTime = gapTime % 86400;
        const hour = this.formatNum(parseInt(lastTime/3600));
        lastTime = lastTime % 3600;
        const minute = this.formatNum(parseInt(lastTime/60));
        const second = this.formatNum(lastTime% 60);
        time = `${hour}:${minute}:${second}`;
        if(!data.clearTimer) this.init.call(this);
      }else {
        this.endFn(data.id);
      }
      this.setData({
        time: '剩余时间:'+time
      });
    },
    formatNum(num) {
      return num > 9 ? num : `0${num}`;
    },
    endFn(id) {
      this.setData({
        flag:true
      })
      this.triggerEvent('callback',{id:id});
    }
  }
})